package com.hz.friends.activity;

import com.avos.avoscloud.AVException;
import com.avos.avoscloud.AVUser;
import com.hz.friends.application.CustomApplication;
import com.hz.friends.serverrequest.ALUserEngine;
import com.hz.friends.serverrequest.ALEngineConfig.CallBack;

import android.os.Bundle;
import android.os.Handler;
import android.text.TextUtils;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.TextView;

public class LevelMessageActivity extends BaseActivity {
	private AVUser user = null;
	private EditText medittext;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_levelmessage);
		init();
		initViews();
		
	}

	@Override
	protected void init() {
		user = ((CustomApplication) getApplication()).user;
	}

	@Override
	protected void initViews() {
		 medittext = (EditText) findViewById(R.id.medittext);
		
		ImageButton imbtn_bar_left = (ImageButton) findViewById(R.id.imbtn_bar_left);
		ImageButton imbtn_bar_right = (ImageButton) findViewById(R.id.imbtn_bar_right);
		Button btn_bar_righ = (Button) findViewById(R.id.btn_bar_righ);
		TextView imbtn_bar_title = (TextView) findViewById(R.id.imbtn_bar_title);
		imbtn_bar_right.setVisibility(View.INVISIBLE);
		btn_bar_righ.setVisibility(View.VISIBLE);
		imbtn_bar_left.setImageResource(R.drawable.ic_leftback_arrow);
		imbtn_bar_title.setText("Leave a message");
		imbtn_bar_left.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				finish();
			}
		});
		btn_bar_righ.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				sendMessage(medittext.getText().toString().trim());			
			}
		});
		
		
 
	}

	@Override
	protected void setViews() {
		// TODO Auto-generated method stub

	}

	@Override
	protected void initEvents() {
		// TODO Auto-generated method stub

	}

	private void sendMessage(String message) {
		if (TextUtils.isEmpty(message)) {
			showToast("请输入留言");
			return;
		}
		createWiatDialog("正在发送");
		ALUserEngine.defauleEngine().leaveAMesage(message, user,
				new CallBack() {

					@Override
					public void done(Object object, AVException avexception) {
						cancleWaitDialog();
						if (avexception != null) {
							showToast("发送失败");
							avexception.printStackTrace();
						} else {
							showToast("发送成功");
						}
					}
				});
	}

}
